﻿<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:local="clr-namespace:ReflectionStudio.Controls"
                    >

    <Style TargetType="local:SyndicationFeedListBox">
        <Setter Property="Padding" Value="1"/>
        <Setter Property="Background" Value="{DynamicResource NormalBackgroundBrush}"/>
        <Setter Property="Foreground" Value="{DynamicResource NormalForegroundBrush}"/>
        <Setter Property="HorizontalContentAlignment" Value="Stretch"/>
        <Setter Property="VerticalContentAlignment" Value="Top"/>
        <Setter Property="IsTabStop" Value="False"/>
        <Setter Property="BorderThickness" Value="0"/>
        <Setter Property="BorderBrush" Value="{DynamicResource NormalBorderBrush}" />
        <Setter Property="ItemContainerStyle">
            <Setter.Value>
                <Style TargetType="ListBoxItem">
                    <Setter Property="Padding" Value="3"/>
                    <Setter Property="HorizontalContentAlignment" Value="Stretch"/>
                    <Setter Property="VerticalContentAlignment" Value="Top"/>
                    <Setter Property="Background" Value="Transparent"/>
                    <Setter Property="BorderThickness" Value="1"/>
                    <Setter Property="Template">
                        <Setter.Value>
                            <ControlTemplate TargetType="ListBoxItem">
                                <Grid Background="{TemplateBinding Background}">
                                    <VisualStateManager.VisualStateGroups>
                                        <VisualStateGroup x:Name="CommonStates">
                                            <VisualState x:Name="Normal">
                                                <Storyboard>
                                                    <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="Flash" Storyboard.TargetProperty="(UIElement.Opacity)">
                                                        <SplineDoubleKeyFrame KeyTime="00:00:00" Value="0.2"/>
                                                        <SplineDoubleKeyFrame KeyTime="00:00:00.2000000" Value="0"/>
                                                    </DoubleAnimationUsingKeyFrames>
                                                </Storyboard>
                                            </VisualState>
                                            <VisualState x:Name="MouseOver">
                                                <Storyboard>
                                                    <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="Flash" Storyboard.TargetProperty="(UIElement.Opacity)">
                                                        <SplineDoubleKeyFrame KeyTime="00:00:00" Value="0.5"/>
                                                        <SplineDoubleKeyFrame KeyTime="00:00:00.2000000" Value="0.2"/>
                                                    </DoubleAnimationUsingKeyFrames>
                                                </Storyboard>
                                            </VisualState>
                                            <VisualState x:Name="Disabled">
                                                <Storyboard>
                                                    <DoubleAnimationUsingKeyFrames Storyboard.TargetName="contentPresenter" Storyboard.TargetProperty="Opacity">
                                                        <SplineDoubleKeyFrame KeyTime="0" Value=".55"/>
                                                    </DoubleAnimationUsingKeyFrames>
                                                </Storyboard>
                                            </VisualState>
                                        </VisualStateGroup>
                                        
                                    </VisualStateManager.VisualStateGroups>
                                    <Rectangle Fill="{DynamicResource NormalForegroundBrush}" Stroke="{x:Null}" x:Name="Flash" Opacity="0"/>
                                    <ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" Margin="{TemplateBinding Padding}" x:Name="contentPresenter" Content="{TemplateBinding Content}" ContentTemplate="{TemplateBinding ContentTemplate}"/>
                                </Grid>
                            </ControlTemplate>
                        </Setter.Value>
                    </Setter>
                </Style>
            </Setter.Value>
        </Setter>
        <Setter Property="RefreshingContent" Value="Refreshing..." />
        <Setter Property="RefreshingContentTemplate">
            <Setter.Value>
                <DataTemplate>
                    <Border>
                        <local:WaitSpin 
                                                Margin="10"
                                                AutoPlay="True"
                                                VerticalAlignment="Center" 
                                                HorizontalAlignment="Center"
                                                HorizontalContentAlignment="Center"
                                                Foreground="#ff7f7f7f"
                                                >

                        </local:WaitSpin>
                    </Border>
                </DataTemplate>
            </Setter.Value>
        </Setter>
        <Setter Property="FeedErrorContent" Value="No results found." />
        <Setter Property="FeedErrorContentTemplate">
            <Setter.Value>
                <DataTemplate>
                    <Border>
                        <ContentControl Content="{Binding}" 
                                        VerticalAlignment="Top" 
                                        HorizontalAlignment="Left"
                                        Margin="10"
                                        Foreground="#ff7f7f7f"
                                        />
                    </Border>
                </DataTemplate>
            </Setter.Value>
        </Setter>
        <Setter Property="ItemTemplate">
            <Setter.Value>
                <DataTemplate>
                    <Border BorderThickness="0,0,0,1" BorderBrush="{DynamicResource NormalBorderBrush}" Padding="0,5,0,5">
                        <Grid>
                            <Grid.Resources>
                                <local:SyndicationItemToUriConverter x:Key="SyndicationItemToUriConverter" />
                                <local:StripHtmlConverter x:Key="StripHtmlConverter" />
                            </Grid.Resources>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="*" />
                            </Grid.ColumnDefinitions>
                            <Grid.RowDefinitions>
                                <RowDefinition Height="Auto" />
                                <RowDefinition Height="Auto" />
                                <RowDefinition Height="Auto" />
                                <RowDefinition Height="Auto" />
                            </Grid.RowDefinitions>

                            <local:WebLink Text="{Binding Title.Text}"
                                       Uri="{Binding Converter={StaticResource SyndicationItemToUriConverter}}"
                                       TextWrapping="Wrap" 
                                       FontWeight="Bold"
                                       />
                            <TextBlock Text="{Binding Converter={StaticResource StripHtmlConverter}, ConverterParameter=150, Path=Summary.Text}" 
                                       Grid.Row="2"
                               HorizontalAlignment="Stretch" VerticalAlignment="Stretch"
                                       />

                            <ItemsControl ItemsSource="{Binding Categories}"
                                          Grid.ColumnSpan="2"
                                          Grid.Row="3">
                                <ItemsControl.ItemsPanel>
                                    <ItemsPanelTemplate>
                                        <WrapPanel />
                                    </ItemsPanelTemplate>
                                </ItemsControl.ItemsPanel>

                                <ItemsControl.ItemTemplate>
                                    <DataTemplate>
                                        <StackPanel Orientation="Horizontal">
                                            <TextBlock Text="[" Opacity="0.3" />
                                            <TextBlock Text="{Binding Name}" Opacity="0.3" />
                                            <TextBlock Text="]  " Opacity="0.3" />
                                        </StackPanel>
                                    </DataTemplate>
                                </ItemsControl.ItemTemplate>
                            </ItemsControl>

                        </Grid>
                    </Border>
                </DataTemplate>
            </Setter.Value>
        </Setter>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="local:SyndicationFeedListBox">
                    <Border BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" CornerRadius="2">
                        <Grid>
                            <ScrollViewer Background="{TemplateBinding Background}" BorderBrush="Transparent" BorderThickness="0" Padding="{TemplateBinding Padding}" x:Name="ScrollViewer"
                                          VerticalScrollBarVisibility="Auto" Foreground="{TemplateBinding Foreground}"
                                      HorizontalScrollBarVisibility="Auto">
                                <ItemsPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"/>
                            </ScrollViewer>

                            <ContentPresenter x:Name="RefreshingContentPresenter"
                                              Content="{TemplateBinding RefreshingContent}"
                                              ContentTemplate="{TemplateBinding RefreshingContentTemplate}"
                                              IsHitTestVisible="False"
                                              Visibility="Collapsed"
                                              />

                            <ContentPresenter x:Name="FeedErrorContentPresenter"
                                              Content="{TemplateBinding FeedErrorContent}"
                                              ContentTemplate="{TemplateBinding FeedErrorContentTemplate}"
                                              IsHitTestVisible="False"
                                              Visibility="Collapsed"
                                              />
                        </Grid>
                    </Border>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
    
</ResourceDictionary>